package com.nowcoder.code.lcof;

import java.util.ArrayList;
import java.util.List;

public class JZ38 {


    public static void main(String[] args) {
        System.out.println(new JZ38().Permutation("abc"));

    }


    public ArrayList<String> Permutation(String str) {
        ArrayList<String> all = new ArrayList<>();
        if (str == null ) {
            return all;
        }
        if (str.length() == 1 || str.isEmpty()) {
            all.add(str);
            return all;
        }

        for (int i = 0; i < str.length(); i++) {
            char first = str.charAt(i);
            if (str.indexOf(first) < i) {
                continue;
            }


            List<String> list = Permutation(str.substring(0, i) + str.substring(i + 1));
            for (String s : list) {
                all.add(first + s);
            }
        }
        return all;
    }

}
